import React, { Component } from 'react';

import { withRouter } from 'react-router-dom';

import { connect } from 'react-redux';

import { 
  NavBar
} from 'antd-mobile';

import './header.less';

const mapState = (state)=> {
  return {
    pageTitle: state.ui.pageTitle,
    isSubpage: state.ui.isSubpage
  }
}

@withRouter
@connect(mapState)

export default class Header extends Component {
  
  render() {

    const navBarProps = {};
    if(this.props.isSubpage) {
      navBarProps.leftContent = "返回";
      navBarProps.onLeftClick = this.props.history.goBack.bind(this);
    }
    return (
      <div className='wgd-header'>
        <NavBar
          {...navBarProps}
        >
          {this.props.pageTitle}
        </NavBar>
      </div>
    )
  }
}
